package com.uperform.coach.tdd.task;

import com.uperform.coach.tdd.BaseFactory;
import com.uperform.coach.tdd.infrastructure.TaskDAO;
import com.uperform.coach.tdd.infrastructure.TaskDO;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

@Component
public class TaskFactory extends BaseFactory {
    private final TaskDAO dao;

    public TaskFactory(TaskDAO dao, JdbcTemplate jdbcTemplate) {
        this.dao = dao;
        this.jdbcTemplate = jdbcTemplate;
    }

    public List<TaskDO> all() {
        return StreamSupport.stream(dao.findAll().spliterator(), false)
                .collect(Collectors.toList());
    }

    public TaskDO save(TaskDO entity) {
        return dao.save(entity);
    }

    @Override
    protected String getTableName() {
        return "t_task";
    }
}
